#include "VSTwoParamAnimBlend.h"
#include "VSGraphicInclude.h"
#include "VSStream.h"
using namespace VSEngine2;
IMPLEMENT_RTTI_NoCreateFun(VSTwoParamAnimBlend,VSAnimBlendFunction)
unsigned int VSTwoParamAnimBlend::DiskUse()const
{
	unsigned int Used = VSAnimBlendFunction::DiskUse();

	Used += sizeof(VSREAL) * 2;

	Used += sizeof(VSREAL) * 2;
	return Used;
}
bool VSTwoParamAnimBlend::Save(VSStream & rStream,unsigned int &iSaveUse)const
{
	if(!VSAnimBlendFunction::Save(rStream,iSaveUse))
		return 0;



	if(!rStream.Write(&m_fParamMax,sizeof(VSREAL) * 2))
		return 0;
	iSaveUse += sizeof(VSREAL) * 2;

	if(!rStream.Write(&m_fParamMin,sizeof(VSREAL) * 2))
		return 0;
	iSaveUse += sizeof(VSREAL) * 2;


	return 1;
}
bool VSTwoParamAnimBlend::Load(VSStream & rStream,unsigned int &iSaveUse)
{	
	if(!VSAnimBlendFunction::Load(rStream,iSaveUse))
		return 0;


	if(!rStream.Read(&m_fParamMax,sizeof(VSREAL) * 2))
		return 0;
	iSaveUse += sizeof(VSREAL) * 2;

	if(!rStream.Read(&m_fParamMin,sizeof(VSREAL) * 2))
		return 0;
	iSaveUse += sizeof(VSREAL) * 2;



	return 1;
}

bool VSTwoParamAnimBlend::Clone(const VSObject *pObject,unsigned int uiType)
{
	const VSTwoParamAnimBlend* Temp = DynamicCast<VSTwoParamAnimBlend>(pObject); 
	if(!Temp)
		return 0;
	if(VSAnimBlendFunction::Clone(pObject,uiType))
	{

		m_fParamMax[0] = Temp->m_fParamMax[0];
		m_fParamMin[0] = Temp->m_fParamMin[0];

		m_fParamMax[1] = Temp->m_fParamMax[1];
		m_fParamMin[1] = Temp->m_fParamMin[1];
		return 1;

	}
	else
	{
		return 0;
	}

}
VSTwoParamAnimBlend::~VSTwoParamAnimBlend()
{

}
VSTwoParamAnimBlend::VSTwoParamAnimBlend()
{
	m_fParam[0] = m_fParam[1] =0.0f;
	m_fParamMax[0] = m_fParamMax[0] =1.0f;
	m_fParamMin[1] = m_fParamMin[1] =-1.0f;
}
VSTwoParamAnimBlend::VSTwoParamAnimBlend(const VSUsedName & ShowName,VSAnimTree * pAnimTree)
:VSAnimBlendFunction(ShowName,pAnimTree)
{
	m_fParam[0] = m_fParam[1] =0.0f;
	m_fParamMax[0] = m_fParamMax[0] =1.0f;
	m_fParamMin[1] = m_fParamMin[1] =-1.0f;
}
bool VSTwoParamAnimBlend::ComputePara(double dAppTime)
{
	for (unsigned int i = 0 ; i < 2 ; i++)
	{
		if (m_fParam[i] < m_fParamMin[i])
		{
			m_fParam[i] = m_fParamMin[i];
		}
		else if (m_fParam[i] > m_fParamMax[i])
		{
			m_fParam[i] = m_fParamMax[i];
		}
	}
	
	return 1;
}